/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.helpdesk.entidades;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Manuel
 */
@Entity
@Table(name = "hd_detalle_ticket")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "HdDetalleTicket.findAll", query = "SELECT h FROM HdDetalleTicket h"),
    @NamedQuery(name = "HdDetalleTicket.findByCodDetTicket", query = "SELECT h FROM HdDetalleTicket h WHERE h.codDetTicket = :codDetTicket"),
    @NamedQuery(name = "HdDetalleTicket.findByFecAsignacion", query = "SELECT h FROM HdDetalleTicket h WHERE h.fecAsignacion = :fecAsignacion"),
    @NamedQuery(name = "HdDetalleTicket.findByCodTecnicoDisp", query = "SELECT h FROM HdDetalleTicket h WHERE h.codTecnico.codTecnico = :codTecnico and  h.codTicket.codEstado.abrevEstado<> :estado and h.codTicket.fecResolucion < :fecha "),
    @NamedQuery(name = "HdDetalleTicket.findByCodTecnico", query = "SELECT h FROM HdDetalleTicket h WHERE h.codTecnico.codTecnico = :codTecnico "),
    @NamedQuery(name = "HdTickets.ShowTicketsBycodJefe", query = "SELECT h FROM HdDetalleTicket h WHERE h.codTecnico.codTecnico = :codTecnico AND h.codTicket.codEstado = :codEstado"),
    @NamedQuery(name = "HdDetalleTicket.findByCodTecnicoAndEstado", query = "SELECT h FROM HdDetalleTicket h WHERE h.codTecnico.codTecnico = :codTecnico AND h.codTicket.codEstado.codEstado = :codEstado"),
    @NamedQuery(name = "HdDetalleTicket.findByEstadoAndTecnico", query = "SELECT count(h) FROM HdDetalleTicket h WHERE  h.codTicket.codEstado.abrevEstado= :codEstado and h.codTecnico.codTecnico = :codTecnico"), 
    @NamedQuery(name = "HdDetalleTicket.findByInbox", query = "SELECT h FROM HdDetalleTicket h WHERE h.codTecnico.codUsuario.codUsuario = :codTecnico AND h.codTicket.codEstado.codEstado NOT IN (8,7,6)")
})
public class HdDetalleTicket implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy= GenerationType.TABLE, generator="DTICKET")
    @TableGenerator(name="DTICKET", 
                    table="tbsequence",
                    pkColumnName="seq_name",
                    valueColumnName="seq_count")
    @Column(name = "COD_DET_TICKET", nullable=false)
    @Basic(optional = false)
    @NotNull
    private Integer codDetTicket;
    @Column(name = "FEC_ASIGNACION")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecAsignacion;
    @JoinColumn(name = "COD_TECNICO", referencedColumnName = "COD_TECNICO")
    @ManyToOne
    private HdTecnicos codTecnico;
    @JoinColumn(name = "COD_TICKET", referencedColumnName = "COD_TICKET")
    @ManyToOne(optional = false)
    private HdTickets codTicket;
    @OneToMany(mappedBy = "codDetTicket")
    private List<HdObservaciones> hdObservacionesList;

    public HdDetalleTicket() {
    }

    public HdDetalleTicket(Integer codDetTicket) {
        this.codDetTicket = codDetTicket;
    }

    public Integer getCodDetTicket() {
        return codDetTicket;
    }

    public void setCodDetTicket(Integer codDetTicket) {
        this.codDetTicket = codDetTicket;
    }

    public Date getFecAsignacion() {
        return fecAsignacion;
    }

    public void setFecAsignacion(Date fecAsignacion) {
        this.fecAsignacion = fecAsignacion;
    }

    public HdTecnicos getCodTecnico() {
        return codTecnico;
    }

    public void setCodTecnico(HdTecnicos codTecnico) {
        this.codTecnico = codTecnico;
    }

    public HdTickets getCodTicket() {
        return codTicket;
    }

    public void setCodTicket(HdTickets codTicket) {
        this.codTicket = codTicket;
    }

    @XmlTransient
    public List<HdObservaciones> getHdObservacionesList() {
        return hdObservacionesList;
    }

    public void setHdObservacionesList(List<HdObservaciones> hdObservacionesList) {
        this.hdObservacionesList = hdObservacionesList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (codDetTicket != null ? codDetTicket.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof HdDetalleTicket)) {
            return false;
        }
        HdDetalleTicket other = (HdDetalleTicket) object;
        if ((this.codDetTicket == null && other.codDetTicket != null) || (this.codDetTicket != null && !this.codDetTicket.equals(other.codDetTicket))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
      //  return "com.helpdesk.entidades.HdDetalleTicket[ codDetTicket=" + codDetTicket + " ]";
        return "Deatalle: "+codDetTicket;
    }
    
}
